# Makefile for Cloud Agent

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod

# Binary name
BINARY_NAME=cloudAgent
BINARY_UNIX=$(BINARY_NAME)

# Default target
all: build-windows build-linux

# Build for current platform
build:
	$(GOBUILD) -o $(BINARY_NAME) -v

# Build for Windows
build-windows:
	GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME).exe -v

# Build for Linux
build-linux:
	GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX)-linux -v

# Build for macOS
build-mac:
	GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX)-macos -v

# Install dependencies
deps:
	$(GOMOD) download

# Run the agent
run:
	$(GOCMD) run main.go

# Run tests
test:
	$(GOTEST) -v ./...

# Clean build artifacts
clean:
	$(GOCLEAN)
	rm -f $(BINARY_NAME)
	rm -f $(BINARY_NAME).exe
	rm -f $(BINARY_UNIX)

# Install the agent
install:
	$(GOBUILD) -o $(GOPATH)/bin/$(BINARY_NAME) -v

# Format source code
fmt:
	$(GOCMD) fmt ./...

# Vet the source code
vet:
	$(GOCMD) vet ./...

# Generate protobuf files
proto:
	protoc --go_out=. --go_opt=paths=source_relative \
		--go-grpc_out=. --go-grpc_opt=paths=source_relative \
		proto/agent.proto

# Help information
help:
	@echo "Makefile commands:"
	@echo "  all          - Build for current platform (default)"
	@echo "  build        - Build for current platform"
	@echo "  build-windows - Build for Windows"
	@echo "  build-linux   - Build for Linux"
	@echo "  build-mac     - Build for macOS"
	@echo "  deps         - Install dependencies"
	@echo "  run          - Run the agent"
	@echo "  test         - Run tests"
	@echo "  clean        - Clean build artifacts"
	@echo "  install      - Install the agent"
	@echo "  fmt          - Format source code"
	@echo "  vet          - Vet the source code"
	@echo "  proto        - Generate protobuf files"
	@echo "  help         - Show this help message"

.PHONY: all build build-windows build-linux build-mac deps run test clean install fmt vet proto help